import QtQuick 2.0
import "Slideshow.js" as Slideshow

Item {
    id: slideshow
    objectName: "slideshow"
    property bool running: false
    property int xStart: 0
    property int yStart: 0
    property int xEnd: -100
    property int yEnd: -100
    property double scaleStart: 1.0
    property double scaleEnd: 1.2
    property int duration: 10000
    property string imagesFolderPath: ""
    property variant excludeFolders: []

    Image {
        id: slide
        width: slideshow.width
        fillMode: Image.PreserveAspectFit
        onStatusChanged: {
            if (status == Image.Null || status == Image.Error)
                Slideshow.slideShowed();
        }
    }
    ParallelAnimation {
        id: animation;
        onRunningChanged: if (running == false) fadeOutAnimation.start()
        NumberAnimation { target: slide; property: "opacity"; to: 1.0; duration: slideshow.duration/8; }
        NumberAnimation { target: slide; property: "x"; from: xStart; to: xEnd; duration: slideshow.duration; easing.type: Easing.InOutQuad }
        NumberAnimation { target: slide; property: "y"; from: yStart; to: yEnd; duration: slideshow.duration; easing.type: Easing.InOutQuad }
        NumberAnimation { target: slide; property: "scale"; from: scaleStart; to: scaleEnd; duration: slideshow.duration; easing.type: Easing.InOutQuad }
    }
    NumberAnimation {
        id: fadeOutAnimation; target: slide; property: "opacity"; to: 0.0;
        onRunningChanged: if (running == false) Slideshow.slideShowed();
        duration: 1500; easing.type: Easing.OutExpo
    }

    onRunningChanged: {
        if (slideshow.running) {
            Slideshow.run();
        } else {
            Slideshow.stop();
        }
    }

    function setSlides(slidesList) {
        if (running) {
            console.log("Slideshow: settings slides while running!")
            return;
        }
        Slideshow.slides = slidesList
    }
}
